﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TVDL4.DAO;
using TVDL4.VO;
namespace TVDL4.BUS
{
    public class ThiNghiemBUS
    {
        private ThiNghiemDAO thinghiemDAO;

            /// <constructor>
            /// Constructor VatLieuBUS
            /// </constructor>
            public ThiNghiemBUS()
            {
                thinghiemDAO = new ThiNghiemDAO() ;
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="tenThiNghiem"></param>
            /// <returns></returns>
            public ThiNghiemVO GetThiNghiemByNam(string tenThiNghiem)
            {
                ThiNghiemVO thinghiemVO = new ThiNghiemVO();
                DataTable dataTable = new DataTable();
                dataTable = thinghiemDAO.SearchByName(tenThiNghiem);
                foreach (DataRow dr in dataTable.Rows)
                {
                    thinghiemVO.KeySL = dr["KEYSL"].ToString();
                    thinghiemVO.TenThiNghiem  = dr["TenThiNghiem"].ToString();
                    thinghiemVO.LoaiVatlieu.KeySL = dr["KEYSLVATLIEU"].ToString();
                    thinghiemVO.LoaiVatlieu.TenVatLieu = dr["TENVATLIEU"].ToString();
                }
                return thinghiemVO;
            }
            public ThiNghiemVO InsertRecord(ThiNghiemVO thinghiemVO)
            {
                return thinghiemDAO.InsertRecord(thinghiemVO);
            }
            public bool UpdateRecord(ThiNghiemVO thinghiemVO)
            {
                return thinghiemDAO.UpdateRecord(thinghiemVO);
            }
            public bool DeleteRecord(string keySL)
            {
                return thinghiemDAO.DeleteRecord(keySL);
            }
            public List<ThiNghiemVO> GetListThiNghiem()
            {
                List<ThiNghiemVO> lstThiNghiem = new List<ThiNghiemVO>();
                ThiNghiemVO thinghiemVO;
                DataTable dataTable = new DataTable();
                dataTable = thinghiemDAO.SearchAll();
                foreach (DataRow dr in dataTable.Rows)
                {
                    thinghiemVO = new ThiNghiemVO();
                    thinghiemVO.KeySL = dr["KEYSL"].ToString();
                    thinghiemVO.TenThiNghiem  = dr["TENTHINGHIEM"].ToString();
                    thinghiemVO.LoaiVatlieu.KeySL  = dr["KEYSLVATLIEU"].ToString();
                    thinghiemVO.LoaiVatlieu.TenVatLieu = dr["TENVATLIEU"].ToString();
                    lstThiNghiem.Add(thinghiemVO);

                }
                return lstThiNghiem;
            }
            public List<ThiNghiemVO> GetThiNghiemByKeySL(string keySL)
            {
                List<ThiNghiemVO> lstThiNghiem = new List<ThiNghiemVO>();
                ThiNghiemVO thinghiemVO;
                DataTable dataTable = new DataTable();
                dataTable = thinghiemDAO.SearchThiNghiemByKeySL(keySL);
                foreach (DataRow dr in dataTable.Rows)
                {
                    thinghiemVO = new ThiNghiemVO();
                    thinghiemVO.KeySL = dr["KEYSL"].ToString();
                    thinghiemVO.TenThiNghiem  = dr["TENTHINGHIEM"].ToString();
                    thinghiemVO.LoaiVatlieu.KeySL = dr["KEYSLVATLIEU"].ToString();
                    thinghiemVO.LoaiVatlieu.TenVatLieu = dr["TENVATLIEU"].ToString();
                    lstThiNghiem.Add(thinghiemVO);
                }
                return lstThiNghiem;
            }
    }
}
